<template>
	<view class="infobtn-container">
		<!-- 底部按钮 -->
		<view class="infobtn-btn">
			<view class="infobtn-btn-col" @click="cancelCollect">
				<image :src="'../static/icons/' + imgurl" mode="widthFix"></image>{{flag == 1 ? '已收藏' : '加入收藏'}}
			</view>
			<view class="infobtn-btn-che" @click="checkAnswer()">
				查看答案
			</view>
		</view>
		<!-- 查看答案 -->
		<view class="infobtn-answer" v-if="show">
			<view style="font-weight: bold;">答案及解析：</view>
			<view style="margin-top: 10rpx;">
				{{data.answer}}
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "infobtn",
		props: {
			data: {
				type: Object,
				default: {}
			},
			coltype: {
				type: Number,
				default: 1
			}
		},
		data() {
			return {
				answer: "默认答案",
				imgurl: "icon_like_c.png",
				flag: 1, // 0代表没有收藏，1代表已经收藏
				show: false, // 内容部分是否显示
			};
		},
		methods: {
			// 取消收藏
			cancelCollect() {
				if (this.flag) {
					this.imgurl = "icon_like.png";
					this.flag = 0;
					uni.showToast({
						title: '取消收藏成功',
						duration: 2000
					});
					// 取消了之后要发送请求，将该数据在收藏表中进行删除
					/* 
					 逻辑
					 */
				} else {
					this.imgurl = "icon_like_c.png";
					this.flag = 1;
					uni.showToast({
						title: '收藏成功',
						duration: 2000
					});
					// 收藏之后要发送请求，将该数据添加到收藏表中
					/* 
					 逻辑
					 */
				}
			},
			// 查看答案
			checkAnswer() {
				this.show = true;
			}
		}
	}
</script>

<style lang="scss">
	.infobtn-btn {
		position: fixed;
		bottom: 0;
		width: 100vw;
		display: flex;
		align-items: center;
		text-align: center;
		line-height: 80rpx;
		color: #fff;
		font-weight: bold;

		.infobtn-btn-col {
			width: 50%;
			height: 100%;
			background-color: #ff976a;

			image {
				width: 50rpx;
				vertical-align: middle;
			}
		}

		.infobtn-btn-che {
			width: 50%;
			height: 100%;
			background-color: #07c160;
		}
	}

	.infobtn-answer {
		padding: 20rpx;
	}
</style>
